#include <iostream>
#include <ctemplate/template.h>
// #include "oj_model.hpp"
#include "oj_model_sql.hpp"

namespace lh_view
{
    using namespace lh_model;
    static std::string template_path = "./template_html/"; 
    class View
    {
    public:
    View(){}
    ~View(){}
    bool AllExpandHtml(const std::vector<Question>& question_list,std::string *html)
    {
        // 1. 形成路径
        std::string src_html = template_path + "all_questions.html";
        // 2. 形成字典
        ctemplate::TemplateDictionary root("all_questions");
        for(const auto& e : question_list)
        {
            ctemplate::TemplateDictionary *sub = root.AddSectionDictionary("question_list");
            sub->SetValue("number",e.number);
            sub->SetValue("title",e.title);
            sub->SetValue("level",e.level);
        }
        // 3. 获取要渲染的html
        ctemplate::Template *tpl = ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);
        tpl->Expand(html,&root);
        return true;
    }
    bool OneExpandHtml(const Question& q, std::string *html)
    {
        std::string src_html = template_path + "question.html";

        ctemplate::TemplateDictionary root("one_question");
        root.SetValue("number",q.number);
        root.SetValue("title",q.title);
        root.SetValue("level",q.level);
        root.SetValue("header",q.header);
        root.SetValue("desc",q.desc);

        ctemplate::Template* tpl = ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);
        tpl->Expand(html,&root);
        return true;
    }

    private:

    };
}